package cn.msqweb.controller;

import cn.msqweb.entity.MemberAddr;
import cn.msqweb.model.Result;
import cn.msqweb.service.MemberAddrService;
import cn.msqweb.util.AuthUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "会员收货地址接口管理")
@RequestMapping("p/address")
@RestController
public class MemberAddrController {
    @Autowired
    private MemberAddrService memberAddrService;

    @ApiOperation("查询会员收货地址列表")
    @GetMapping("list")
    public Result<List<MemberAddr>> loadMemberAddrList() {
        List<MemberAddr> memberAddrList = memberAddrService.queryMemberAddrListByOpenId(AuthUtils.getLoginMemberOpenId());
        return Result.success(memberAddrList);
    }

    //    p/address/addrInfo/12
    @GetMapping("getMemberAddrById")
    public Result<MemberAddr> getMemberAddrById(@RequestParam Long id) {
        MemberAddr memberAddr = memberAddrService.getById(id);
        return Result.success(memberAddr);
    }
}
